const ccu = {
  state: {
    ccuList: [],
    ccuListNcp: []
  },
  mutations: {
    setCcuList (state, data) {
      state.ccuList = data
    },
    setCcuListNcp (state, data) {
      state.ccuListNcp = data.map(item => {
        return {
          ...item,
          type: 'ccu'
        }
      })
    },
    setCcuListNcpState (state, data) {
      if (state.ccuListNcp.find(item => item.id === data.id)) {
        state.ccuListNcp.find(item => item.id === data.id).is_connected = data.is_connected
      }
    }
  },
  actions: {
    async getCcuList (context) {
      let response = await context.dispatch(`axios`, {
        method: 'get',
        url: '/api/abs/devices/ccus/'
      })
      context.commit('setCcuList', response.data)
    },
    async getCcuListNcp (context) {
      let response = await context.dispatch(`axios`, {
        method: 'get',
        url: '/api/abs/ncp/ccu_list/'
      })
      context.commit('setCcuListNcp', response.data)
    }
  }
}
export default ccu
